package initialization

import (
	"blog/app/common"
	"github.com/spf13/viper"
)

// 配置
func SetConfig(name string) {
	var C common.Conf
	vper := viper.New()
	vper.SetConfigName(name)     // 配置文件的名字
	vper.SetConfigType("json")   // 配置文件的类型
	vper.AddConfigPath("./conf") // 配置文件的路径
	if err := vper.ReadInConfig(); err != nil {
		panic(err)
	}
	C.DbUser = vper.Get("db_user").(string)
	C.DbPass = vper.Get("db_pass").(string)
	C.DbHost = vper.Get("db_host").(string)
	C.DbPort = vper.Get("db_port").(float64)
	C.DbName = vper.Get("db_name").(string)
	C.DbMaxIdleConn = vper.Get("db_max_idle_conn").(float64)
	C.DbMaxOpenConn = vper.Get("db_max_open_conn").(float64)

	C.Port = ":" + vper.Get("port").(string)

	common.C = C

}
